package com.yeyks.util;

import com.google.common.base.Splitter;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Author fuchangshuai
 * @date 2019/3/11 10:49 AM
 */
public class Splitters {

    public static final Splitter DOT = Splitter.on(".").omitEmptyStrings().trimResults();
    public static final Splitter COMMA = Splitter.on(",").omitEmptyStrings().trimResults();
    public static final Splitter COLON = Splitter.on(":").omitEmptyStrings().trimResults();
    public static final Splitter AT = Splitter.on("@").omitEmptyStrings().trimResults();
    public static final Splitter SLASH = Splitter.on("/").omitEmptyStrings().trimResults();
    public static final Splitter SPACE = Splitter.on(" ").omitEmptyStrings().trimResults();
    public static final Splitter UNDERSCORE = Splitter.on("_").omitEmptyStrings().trimResults();
    public static final Splitter EQUAL = Splitter.on("=").omitEmptyStrings().trimResults();
    public static final Splitter QUOTE = Splitter.on("\"").omitEmptyStrings().trimResults();
    public static final Splitter QUESTION = Splitter.on("?").omitEmptyStrings().trimResults();
    public static final Splitter ENTER = Splitter.on("\n").omitEmptyStrings().trimResults();
    public static final Splitter SEMICOLON = Splitter.on(";").omitEmptyStrings().trimResults();

    public Splitters() {
    }

    public static List<Long> splitToLong(CharSequence sequence, Splitter splitter) {
        List<String> ss = splitter.splitToList(sequence);
        ArrayList<Long> res = Lists.newArrayListWithCapacity(ss.size());
        for (String s : ss) {
            res.add(Long.valueOf(s));
        }
        return res;
    }

    public static List<Integer> splitToInteger(CharSequence sequence, Splitter splitter) {
        List<String> ss = splitter.splitToList(sequence);
        ArrayList<Integer> res = Lists.newArrayListWithCapacity(ss.size());

        for (String s : ss) {
            res.add(Integer.valueOf(s));
        }
        return res;
    }

    public static List<String> splitToString(CharSequence sequence, Splitter splitter) {
        List<String> ss = splitter.splitToList(sequence);
        ArrayList<String> res = Lists.newArrayListWithCapacity(ss.size());
        res.addAll(ss);
        return res;
    }

//    public static void main(String[] args) {
//        String str = "信息填错,行程有变,满房,其他app更便宜,酒店质量差,前台价格更优惠,app信息错误,其他";
//        System.out.println(Splitters.splitToString(str, Splitters.COMMA).toString());
//    }
}
